package pack;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Luck {
    public static void main(String[] args) {
        String fileName1="E:\\data\\16信本2班Java作业一\\面向对象程序设计Java2016级信本2班1606101025黄宇作业1";
        String fileName2="E:\\data\\16信本2班Java作业一\\面向对象程序设计Java2016级信本2班1606101027程嘉星作业1";
        FileInputStream fis1=null;
        FileInputStream fis2=null;
        try {
            fis1=new FileInputStream(fileName1);
            fis2=new FileInputStream(fileName2);
            int len1=fis1.available();
            int len2=fis2.available();
            if (len1==len2){
                byte[] data1=new byte[len1];
                byte[] data2=new byte[len2];
                fis1.read(data1);
                fis2.read(data2);
                for (int i=0;i<len1;i++){
                    if (data1[i]!=data2[i]){
                        System.out.println("文件内容不一样");
                        return;
                    }
                }
                System.out.println("两个文件完全相同");
            }else {

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fis1!=null){
                try {
                    fis1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis2!=null){
                try {
                    fis2.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
